package com.cc.demo.service;

import com.cc.demo.dto.TransactionMessage;
import com.cc.demo.entity.TransactionEventMessage;

import java.util.Optional;

public interface TransactionEventMessageService {

    /**
     * 存储待确认的message(需要二次确认的模式，强一致性)
     *
     * @param transactionEventMessage
     * @return
     */
    TransactionEventMessage saveMessageWaitingConfirm(TransactionEventMessage transactionEventMessage);

    /**
     * 将message确认为可发送，并进行发送
     *
     * @param id
     */
    void confirmAndSendMessage(Integer id);


    /**
     * 保存message并发送message(直接省略待确认，可接受数据丢失)
     *
     * @param transactionEventMessage
     * @return
     */
    boolean saveAndSendMessage(TransactionEventMessage transactionEventMessage);


    /**
     * 直接发送message
     *
     * @param transactionEventMessage
     */
    void directSendMessage(TransactionEventMessage transactionEventMessage);


    /**
     * 重发message
     *
     * @param transactionEventMessage
     */
    void resendMessage(TransactionEventMessage transactionEventMessage);


    /**
     * 根据messageId重发某条消息
     *
     * @param id
     */
    void resendMessageById(Integer id);


    /**
     * 获取message
     *
     * @param transactionEventMessage
     * @return
     */
    Optional<TransactionEventMessage> findTransactionEventMessage(TransactionEventMessage transactionEventMessage);


    TransactionEventMessage convertMessageToTransactionEventMessage(TransactionMessage<?> transactionMessage);


    TransactionMessage<?> convertTransactionEventMessageToMessage(TransactionEventMessage transactionEventMessage);


    Optional<TransactionEventMessage> getMessageById(Integer id);


    void setTransactionEventMessageToCompleted(TransactionEventMessage transactionEventMessage);

    void setTransactionEventMessageToFailed(TransactionEventMessage transactionEventMessage);

    /**
     * 批量发送可发送的数据
     * TODO 需要限制条数
     */
    void batchSendConfirmedMessage();

}
